package com.example.gezihua.myapplication.pull;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.AbsListView;
import android.widget.ListView;

/**
 * Created by gezihua on 16-12-21.
 */

public class PullListView extends ListView implements IPullView {
    boolean mCanScroll = false;


    public PullListView(Context context) {
        super(context);
        addOnScrollListener();
    }

    public PullListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        addOnScrollListener();
    }

    public PullListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        addOnScrollListener();
    }

    private void addOnScrollListener() {
        setOnScrollListener(new OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {

            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                Log.e("suj","firstVisibleItem"+firstVisibleItem);
                mCanScroll = (firstVisibleItem == 0)||(visibleItemCount==0);

            }
        });
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        Log.e("suj","PullListView.................onTouchEvent"+ev.toString());
        return super.onTouchEvent(ev);
    }

    @Override
    public boolean canScroll() {
        return mCanScroll;
    }

    @Override
    public int getPullTransY() {
        return (int) getTranslationY();
    }

    @Override
    public void setPullTransY(int i) {
        Log.e("suj","trans"+i);
        setTranslationY(i);
    }
}
